Skip to main content

libobs_wrapper\data\object/
mod.rs

1use std::fmt::Debug;
2
3use crate::{
4    data::{ImmutableObsData, ObsData, ObsObjectUpdater},
5    macros::trait_with_optional_send_sync,
6    runtime::ObsRuntime,
7    unsafe_send::{NativePointer, SmartPointerSendable},
8    utils::{ObsError, ObsString},
9};
10
11mod macros;
12pub(crate) use macros::*;
13
14trait_with_optional_send_sync! {
15    #[doc(hidden)]
16    pub trait ObsObjectTraitPrivate: Debug {
17        /// Replaces the settings data of the object. This should only be called if the actual OBS object has been updated.
18        ///
19        /// DO NOT USE THIS METHOD UNLESS YOU KNOW WHAT YOU ARE DOING.
20        fn __internal_replace_settings(&self, settings: ImmutableObsData) -> Result<(), ObsError>;
21        /// Replaces the hotkey data of the object. This should only be called if the actual OBS object has been updated.
22        ///
23        /// DO NOT USE THIS METHOD UNLESS YOU KNOW WHAT YOU ARE DOING.
24        fn __internal_replace_hotkey_data(&self, hotkey_data: ImmutableObsData)
25            -> Result<(), ObsError>;
26    }
27}
28
29#[allow(private_bounds)]
30/// Trait representing an OBS object.
31/// A OBs object has an id, a name, `settings` and `hotkey_data`.
32pub trait ObsObjectTrait: ObsObjectTraitPrivate {
33    #[doc(hidden)]
34    type Native: NativePointer;
35
36    fn runtime(&self) -> &ObsRuntime;
37    fn settings(&self) -> Result<ImmutableObsData, ObsError>;
38    fn hotkey_data(&self) -> Result<ImmutableObsData, ObsError>;
39
40    fn id(&self) -> ObsString;
41    fn name(&self) -> ObsString;
42
43    /// Updates the settings of this output. Fails if active.
44    fn update_settings(&self, settings: ObsData) -> Result<(), ObsError>;
45
46    /// Updates the object with the current settings.
47    /// For examples please take a look at the [Github repository](https://github.com/libobs-rs/libobs-rs/blob/main/examples).
48    fn create_updater<'a, T: ObsObjectUpdater<'a, ToUpdate = Self> + Send + Sync>(
49        &'a mut self,
50    ) -> Result<T, ObsError>
51    where
52        Self: Sized + Send + Sync,
53    {
54        let runtime = self.runtime().clone();
55        T::create_update(runtime, self)
56    }
57
58    /// Stable opaque identity for this native object. It is scoped to the owning runtime.
59    fn object_id(&self) -> crate::unsafe_send::NativeObjectId {
60        self.__native_handle().native_id()
61    }
62
63    #[doc(hidden)]
64    fn __native_handle(&self) -> SmartPointerSendable<Self::Native>;
65}